import 'package:erp/widgets/form1/form_builder.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

class SaleProjectDescriptionController extends GetxController {
  final FormManagement formManagement = FormManagement();

  Map<String, dynamic> formData = {
    'detailContent': '',
    'detailAmount': '',
    'detailOwner': '',
    'detailMemo': '',
  };

  bool readOnly = false;

  @override
  void onInit() {
    var dynamic = Get.arguments;
    if (dynamic != null && dynamic is Map) {
      final map = dynamic;
      // 是否只读模式
      if (map['readOnly'] != null && map['readOnly'] is bool) {
        readOnly = map['readOnly'];
      }
      if (map['data'] != null) {
        formData = map['data'];
      }
    }
    super.onInit();
  }

  void cancel() {
    Get.back();
  }

  void save() async {
    var validateResult1 = formManagement.validate();
    if (!validateResult1.result) {
      EasyLoading.showError(validateResult1.message ?? "");
      return;
    }
    Get.back(result: {"data": formManagement.data});
  }
}
